import axios from 'axios'
import store from '../store'
import { getToken } from './auth'

const request = axios.create({
  // baseURL: 'http://localhost:3000'
})

// 请求拦截器
request.interceptors.request.use(config => {
  if (store.getters.token) {
    // 给请求头加上token
    config.headers['token'] = getToken()
  }
  return config
}, error => {
  console.log(error)
  return Promise.reject(error)
})

export default request
